Skip to content

Commit

Permalink
fix launch path not accessible crash
Browse files Browse the repository at this point in the history
  • Loading branch information
yanue committed Oct 14, 2023
1 parent 6ac55b8 commit a4e5b4e
Show file tree
Hide file tree
Showing 7 changed files with 809 additions and 653 deletions.
Binary file modified Build/v2ray-core/geoip.dat
Binary file not shown.
1,382 changes: 757 additions & 625 deletions Build/v2ray-core/geosite.dat

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions V2rayU.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 4.0.1;
CURRENT_PROJECT_VERSION = 4.0.3;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = RJYEH6TCJD;
ENABLE_ONLY_ACTIVE_RESOURCES = YES;
Expand All @@ -847,7 +847,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 4.0.preview;
MARKETING_VERSION = 4.0.0;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = net.yanue.V2rayU;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -869,7 +869,7 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 4.0.1;
CURRENT_PROJECT_VERSION = 4.0.3;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = RJYEH6TCJD;
ENABLE_ONLY_ACTIVE_RESOURCES = YES;
Expand All @@ -880,7 +880,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 4.0.preview;
MARKETING_VERSION = 4.0.0;
ONLY_ACTIVE_ARCH = NO;
PRODUCT_BUNDLE_IDENTIFIER = net.yanue.V2rayU;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
16 changes: 9 additions & 7 deletions V2rayU/MainMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ class MenuController: NSObject, NSMenuDelegate {

func setStatusMenuTip(pingTip: String) {
do {
if self.statusMenu.item(withTag: 1) != nil {
self.statusMenu.item(withTag: 1)!.title = pingTip
DispatchQueue.main.async {
if self.statusMenu.item(withTag: 1) != nil {
self.statusMenu.item(withTag: 1)!.title = pingTip
}
}
}
}
Expand All @@ -114,11 +116,11 @@ class MenuController: NSObject, NSMenuDelegate {
let _subMenus = getServerMenus()
lock.lock()
do {
serverItems.submenu = _subMenus
// fix: must be used from main thread only
if configWindow != nil && configWindow.serversTableView != nil {
DispatchQueue.main.async {
configWindow.serversTableView.reloadData()
DispatchQueue.main.async {
self.serverItems.submenu = _subMenus
// fix: must be used from main thread only
if configWindow != nil && configWindow.serversTableView != nil {
configWindow.serversTableView.reloadData()
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions V2rayU/Ping.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ class PingSpeed: NSObject {
NSLog("ping inPing")
return
}

// make sure core file
V2rayLaunch.checkV2rayCore()
// in ping
inPing = true

killAllPing()

fastV2rayName = ""
unpingServers = [String: Bool]()
let itemList = V2rayServer.list()
if itemList.count == 0 {
inPing = false
return
}
let langStr = Locale.current.languageCode
Expand All @@ -46,8 +51,6 @@ class PingSpeed: NSObject {
pingTip = "Ping Speed - 测试中"
}
menuController.setStatusMenuTip(pingTip: pingTip)
// in ping
inPing = true
let pingQueue = DispatchQueue(label: "pingQueue", qos: .background, attributes: .concurrent)
for item in itemList {
unpingServers[item.name] = true
Expand Down
3 changes: 3 additions & 0 deletions V2rayU/Util.swift
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,9 @@ func killAllPing(){
let pskillCmd = "ps aux | grep v2ray | grep '.V2rayU/.config.' | awk '{print $2}' | xargs kill"
let msg = shell(launchPath: "/bin/bash", arguments: ["-c", pskillCmd])
NSLog("killAllPing: \(String(describing: msg))")
let rmPingJsonCmd = "rm -f ~/.V2rayU/.config.*.json"
let msg1 = shell(launchPath: "/bin/bash", arguments: ["-c", rmPingJsonCmd])
NSLog("rmPingJson: \(String(describing: msg1))")
}

func killSelfV2ray(){
Expand Down
44 changes: 30 additions & 14 deletions V2rayU/V2rayLaunch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,48 +48,53 @@ class V2rayLaunch: NSObject {
}

// make sure new version
print("install", AppResourcesPath)
NSLog("install", AppResourcesPath)
var needRunInstall = false
if !FileManager.default.fileExists(atPath: v2rayCoreFile) {
print("\(v2rayCoreFile) not exists,need install")
NSLog("\(v2rayCoreFile) not exists,need install")
needRunInstall = true
}
if !FileManager.default.isExecutableFile(atPath: v2rayCoreFile) {
NSLog("\(v2rayCoreFile) not accessable")
needRunInstall = true
}
if !FileManager.default.fileExists(atPath: v2rayCorePath+"/geoip.dat") {
print("\(v2rayCorePath)/geoip.dat not exists,need install")
NSLog("\(v2rayCorePath)/geoip.dat not exists,need install")
needRunInstall = true
}
if !FileManager.default.fileExists(atPath: v2rayUTool) {
print("\(v2rayUTool) not exists,need install")
NSLog("\(v2rayUTool) not exists,need install")
needRunInstall = true
}
if !FileManager.default.fileExists(atPath: PACAbpFile) {
print("\(PACAbpFile) not exists,need install")
NSLog("\(PACAbpFile) not exists,need install")
needRunInstall = true
}
if !FileManager.default.fileExists(atPath: GFWListFilePath) {
print("\(GFWListFilePath) not exists,need install")
NSLog("\(GFWListFilePath) not exists,need install")
needRunInstall = true
}
if !FileManager.default.fileExists(atPath: PACUserRuleFilePath) {
print("\(PACUserRuleFilePath) not exists,need install")
NSLog("\(PACUserRuleFilePath) not exists,need install")
needRunInstall = true
}

// V2rayUTool version
let toolVersion = shell(launchPath: v2rayUTool, arguments: ["version"])

// use /bin/bash to fix crash when V2rayUTool is not exist
let toolVersion = shell(launchPath: "/bin/bash", arguments: ["-c", "\(v2rayUTool) version"])
NSLog("toolVersion - \(v2rayUTool): \(String(describing: toolVersion))")
if toolVersion != nil {
let _version = toolVersion ?? "" // old version
if _version.contains("Usage:") {
print("\(v2rayUTool) old version,need install")
NSLog("\(v2rayUTool) old version,need install")
needRunInstall = true
} else {
if !(_version >= "4.0.0") {
print("\(v2rayUTool) old version,need install")
NSLog("\(v2rayUTool) old version,need install")
needRunInstall = true
}
}
} else {
print("\(v2rayUTool) not exists,need install")
NSLog("\(v2rayUTool) not exists,need install")
needRunInstall = true
}

Expand Down Expand Up @@ -149,7 +154,7 @@ class V2rayLaunch: NSObject {
static func runAtStart(){
// clear not available
V2rayServer.clearItems()

// install before launch
V2rayLaunch.install()

Expand Down Expand Up @@ -318,6 +323,17 @@ class V2rayLaunch: NSObject {
}
}

static func checkV2rayCore() {
if !FileManager.default.fileExists(atPath: v2rayCoreFile) {
print("\(v2rayCoreFile) not exists,need install")
self.install()
}
if !FileManager.default.isExecutableFile(atPath: v2rayCoreFile) {
print("\(v2rayCoreFile) not accessable")
self.install()
}
}

static func setSystemProxy(mode: RunMode) {
self.checkV2rayUTool()

Expand Down

0 comments on commit a4e5b4e

Please sign in to comment.